<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui,chosen'}){%>
    <style type="text/css">
        body{padding-top:10px;
            padding-left: 10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>
<div class="row">
    <div class="col-sm-12">
        <div class="ibox-content" style="padding:15px 20px 0px 20px;">
            <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                <div class="form-group">
                    <label class="control-label col-sm-1">供应商:</label>
                    <div class="col-sm-2">
                        <input type="text" id="supplierName" name="supplierName" class="form-control">
                    </div>
                    <label class="control-label col-sm-1">质检结果:</label>
                    <div class="col-sm-2">
                        <select  id="qualityResult" name="qualityResult" class="form-control" >
                            <option value="">请选择</option>
                            <option value="质检通过">质检通过</option>
                            <option value="质检未通过">质检未通过</option>
                            <option value="二次质检">二次质检</option>
                        </select>
                    </div>
                    <label class="control-label col-sm-1">质检日期:</label>
                    <div class="col-sm-2">
                        <input type="text" id="qDate" name="qualityDate" class="form-control">
                    </div>
                    <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                </div>
            </form>
        </div>
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">

            <!-- START 操作按钮 -->
            <!-- END 操作按钮 -->

            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-url="/sea/supply/quality/findByCnd.do"
                   data-page-size="15"
                   class="table table-striped table-hover"
            >
            </table>
            <!-- END 数据表格 -->
        </div>
    </div>
</div>


<!-- START 内容部分 -->
<div class="container" style="display: none;overflow-x: hidden;max-width: 600px" id="layer_window">
    <form class="form-horizontal" id="info-form" enctype="multipart/form-data" autocomplete="off" >
        <input type="hidden" name="id" id="id">
        <br />
        <div class="form-group" style="max-width: 600px;min-width: 580px">
            <label class="control-label col-sm-4">选择文件:</label>
            <div class="col-sm-6">
                <a class="club-import-btn ">
                    <input type="file" id="importSession" name="importSession">
                </a>
                <input type="hidden" name="qualityFile" id="qualityFile">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-3 col-sm-offset-1">选择质检日期:</label>
            <div class="col-sm-6">
                <input type="text" id="qualityDate" name="qualityDate" value="" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-3 col-sm-offset-1">备注:</label>
            <div class="col-sm-6">
                <textarea id="qualityRemark" name="qualityRemark" class="form-control"  rows="3"></textarea>
            </div>

        </div>
    </form>
    <div class="form-group">
        <div class="col-sm-offset-4 col-sm-10">
            <button type="submit" class="save-btn btn btn-primary">
                <i class="fa fa-save"></i> 保存
            </button>
        </div>
    </div>
</div>
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,chosen,chosen-demo'}){}%>
<script>
    var $relatedTable = $('#relatedTable');
    laydate.render({
        elem: '#qualityDate',
        type: 'date',
        trigger: 'click', //修改触发方式
        format: 'yyyy-MM-dd'
    });
    laydate.render({
        elem: '#qDate',
        type: 'month',
        trigger: 'click'
    });
    $(function(){
        //START 表格配置
        $relatedTable.bootstrapTable({
            columns: [
                {
                    title: '柜号',
                    field: 'createPlanNo',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '供应商',
                    field: 'supplierName',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '质检数量',
                    field: 'qualityNumber',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '质检结果',
                    field: 'qualityResult',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '质检报告',
                    field: 'qualityFile',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(null!=v && v!=''){
                            var result='<button  class="download-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">';
                            result+='<i class="fa fa-download" aria-hidden="true"></i> <a href="'+v+'" download style="color: white">下载附件</a>';
                            result+='</button>';
                            return result;
                        }else{
                            return '';
                        }
                    }
                },{
                    title: '质检时间',
                    field: 'qualityDate',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '备注',
                    field: 'qualityRemark',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }

            ],
            onLoadSuccess : function(){
                $(".import-btn").on('click',function () {
                    var id = $(this).attr('data-val');
                    $("#id").val(id);
                    layer.open({
                        type:1,
                        title:'导入明细',
                        area:['600px','400px'],
                        skin:'layer-window',
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_window')
                    });
                });
            }
        });

    });


    function optFormatter(value,row){
        var content = '';
        content += '&nbsp;<button class="import-btn btn btn-xs btn-success" data-val="'+row.id+'" title="导入质检报告">导入质检报告</button>';
        return content;
    }



    $("#productBigClassId").change(function () {
        var parentId=$("#productBigClassId").val();
        getCategory(parentId,1);
    });
    $("#productMidClassId").change(function () {
        var parentId=$("#productMidClassId").val();
        getCategory(parentId,2);
    });

    function getCategory(parentId,type) {
        $.ajax({
            url:'/sea/product/category/findByParentId',
            data:{
                id:parentId
            },
            type:'post',
            success:function (data) {
                var list=data;
                if(list.length>0){
                    var category='<option value="">全部分类</option>';
                    for(var i=0;i<list.length;i++){
                        category+='<option value="'+list[i].id+'">'+list[i].categoryName+'</option>';
                    }
                    if(type=='1') {
                        $("#productMidClassId").html(category);
                    }
                    if(type=='2'){
                        $("#productClassId").html(category);
                    }
                }
            }
        });
    }

    $("#importSession").on("change",function(){
        var formFile = new FormData($('#info-form')[0]);
        var index=layer.load(1, {
            shade: [0.1,'#fff'],
            zIndex : 1111//0.1透明度的白色背景
        });
        $.ajax({
            url: "/upload/uploadFile",
            data: formFile,
            type: "post",
            processData: false,//用于对data参数进行序列化处理 这里必须false
            contentType: false, //必须
            success: function (data) {
                if(data.ok){
                    parent.layer.msg("上传成功！",{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    $("#qualityFile").val(data.data);
                    layer.close(index);
                }else{
                    parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            },
        });
    });


    //提交表单
    $('.save-btn').on('click',function(){
        var qualityDate=$("#qualityDate").val();
        if(qualityDate==''){
            parent.layer.msg('请先选择质检日期！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
            return;
        }

        //数据提交
        $.post('/sea/supply/quality/usave.do',$('#info-form').serialize(),function(data){
            if( data.ok ){
                parent.layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
                    $relatedTable.bootstrapTable('refresh');
                    layer.closeAll(); //关闭弹窗
                });
            }else{
                parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
            }
        });
    });

    // 条件查询
    $('.search-btn').on('click',function () {
        $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/supply/quality/findByCnd.do?'+$('#search-form').serialize() });
    });


</script>
</body>
</html>
